package com.mera.tektronix.csviewer.transformers;

import com.mera.tektronix.csviewer.common.dto.DepartmentDto
import com.mera.tektronix.csviewer.domain.*

public class DepartmentTransformer extends AbstractTransformer<DepartmentDto, Department> {

	@Override
	protected Department getDomainInstance(DepartmentDto dto) {
		if(dto.id != null) {
			return Department.get(dto.id);
		}
		return new Department();
	}

	@Override
	protected DepartmentDto getDtoInstance(Department domain) {
		return new DepartmentDto();
	}

	@Override
	protected void transformDtoToDomainInternal(DepartmentDto dto, Department domain) {		
		domain.name = dto.name;
		domain.email = dto.email;
		domain.phone = dto.phone;
		domain.company = Company.get(dto.companyId);
	}

	@Override
	protected void transformDomainToDtoInternal(Department domain, DepartmentDto dto) {		
		dto.id = domain.id;
		dto.name = domain.name;
		dto.email = domain.email;
		dto.phone = domain.phone;
		dto.companyId = domain.company.id;
	}

}
